<?php

/*
 * 汽车之家导购 数据上传处理
 * @package    system
 * @author     Sameal
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 2e5a4dd6e4ae692075fded0ccf9121395eeabde5 $
 */
defined('IN_IXDCW') or exit('Access Denied');
function getParamCatid($catname) {
	switch ($catname) {
		//固有分类
		case '精彩广告':
			return '3271';
			break;
		case '新车视频':
			return '3274';
			break;
		case '试驾评测':
			return '3275';
			break;
		case '生活娱乐':
			return '3277';
			break;
		case '用车玩车':
			return '3273';
			break;
		case '车展视频':
			return '5154';
			break;
		//非分类	
		case '精彩广告视频':
			return '3271';
			break;
		case '新车视频':
			return '3274';
			break;
		case '汽车评测视频':
			return '3275';
			break;
		case '汽车资讯视频':
			return '3277';
			break;
		case '用车玩车视频':
			return '3273';
			break;
		case '汽车视频':
			return '5154';
			break;
			
		case '卡车文化':
			return '3273';
			break;
		case '卡车宣传广告':
			return '3271';
			break;
		case '卡车赛事':
			return '3277';
			break;
	}
	return '0';
}
$params = array(
	'maxid'     => isset($_GET['maxid']) ? $_GET['maxid'] : 0,
	'id'        => isset($_GET['id']) && !empty($_GET['id']) ? $_GET['id'] : 0,
	'startTime' => isset($_GET['startTime']) ? $_GET['startTime'] : time(),
	'limit'     => 1,
	'interval'  => 4,
	'debug'     => '',
	'moduleid'  => 10, // 资讯 26 导购23 行情 24
	'catid'     => 0, // 3592 试驾体验   3593 新车图解    3594   购车手册    3595  车型对比
	'picAdd'    => 'http://www.autohome.com.cn/',
	'siteName'  => '汽车之家',
	'userid'    => '1',
	'username'  => 'xddlmaster', // id
	'timeType'  => 4, // 1 2013-07-17 10:07:56  2 2013-07-17    3 2013年07月07日
	'dtime'     =>time()-86400,
);

$fields = array(
	'time'     => 'time', // 时间字段
	'title'    => 'title', // 标题字段
	'id'       => 'ID', // id
	'copyfrom' => 'comefrom', // from
);

if($Usubmit) {

		//过滤 火车头传入参数 有可能不存在此参数 火车头 导出[db:XXXX]
		foreach($upinfo as $key => $value){
			if(is_string($value)){
				if(strpos(' '.$value,'[db:') == 1){
					$upinfo[$key] = '';
				}else{
					$upinfo[$key] = trim($upinfo[$key]);
				}
			}
		}

		$title = strlen($upinfo['title2']) >= 3  ? $upinfo['title2'] : $upinfo['title'];

		if(strlen($title) < 3){
			echo("ERROR: 跳过:空标题/长度<3<br>");
			exit;
		}else{
			if($db->getOne("select * from {$db->getPre()}video where title = '$title'")){
				echo("ERROR: 跳过:标题已存在<br>");
				exit;
			}
		}

		$time = strtotime($upinfo['time2']) ? strtotime($upinfo['time2']) : strtotime($upinfo['time']);
		$time = $time ? timetodate($time,'Y-m-d H:i:s') : timetodate($DT_TIME,'Y-m-d H:i:s');

	//	$areaid = Area::area2id($upinfo['area']);
		/*
		if (in_array($upinfo['type'], array('其他媒体转载', '技术部测试', '汽车行情', '汽车动态'))) {
			echo("ERROR: 跳过:其他媒体转载<br>");
			exit;
		}
		*/
		$ids = AutoImport::match($title . $upinfo['pinpai'].$upinfo['chexing'].$upinfo['carname']);
		/*
		if (!$upinfo['carname']) {
			echo("ERROR:跳过:空车型<br>");
			exit;
		}
		*/
	/*
		if (trim($upinfo['content-15']) != '' && trim($upinfo['content-15']) != '[pagebreak]' && trim($upinfo['content-15']) != trim($upinfo['content-1'])) {
			echo("ERROR:跳过:未采集完整<br>");
			exit;
		}
*/
	/*
		if (trim($upinfo['daohang'])) {
			$upinfo['content-1'] = trim(str_replace('[pagebreak]','',$upinfo['content-1']));
			if(empty($upinfo['content-1'])){
				echo("ERROR:跳过:空分页内容<br>");
				exit;
			}
			$content = $upinfo['content-1'];

			for($i=2;$i<=15;$i++){
				$upinfo['content-'.$i] = trim(str_replace('[pagebreak]','',$upinfo['content-'.$i]));
				if($upinfo['content-'.$i] == '' or $upinfo['content-'.$i] == $upinfo['content-1']){
					break;
				}else{
					$content .= '<hr style="page-break-after:always;" class="ke-pagebreak" />'.$upinfo['content-'.$i];
				}
			}

			$subtitle='';
			foreach(explode('\n',$upinfo['daohang']) as $subdaohang){
				if(trim($subdaohan)){
					$subtitle .= PHP_EOL.trim($subdaohang);
				}
			}
		}

		if (empty($content)) {
			$content = trim(str_replace('[pagebreak]','',$upinfo['content-all']));
		}

//		$content = preg_replace("/\[pagebreak\]\s+$/", '', $content);

		if (empty($content)) {
			echo("ERROR:跳过:空内容<br>");
			exit;
		}
*/
//        $content_thumb = $content;
    //    $content_info = $content;
  //      $content_info           = Post::clearLink($content_info);

     //   $content_info           = AutoImport::saveRemotes($content_info, 'jpg|jpeg|gif|png|bmp', $params['moduleid'], $params['userid'], strtotime($time), $params['picAdd']);
    //    $content_info            = AutoImport::fullUrl($content_info, 'jpg|jpeg|gif|png|bmp', $params['picAdd']);
		$thumb             = AutoImport::saveThumbs('<img src="'.$upinfo['thumb'].'">', 1, 120, 90, $params['moduleid'], $params['userid'], strtotime($time), $params['picAdd']);



		$moduleid=10;
		$file = 'index';
		$action = 'add';
		$forward=
		$itemid = '0';
		$post['catid'] = getParamCatid($upinfo['crumbs2'] ? $upinfo['crumbs2'] : $upinfo['crumbs']);;
		$post['arbid'][] = $ids[0] ? $ids[0] : '0';
		$post['arcid'][] = $ids[2] ? $ids[2] : '0';
		$post['armid'][] = '0';
		$post['title'] = $title;
		$post['thumb'] = $thumb;
		$post['content']=$upinfo['content'];
		$post['tag'] = '';
		$post['status'] = '2';
		$post['addtime'] = $time;
		$post['upinfo'] = 'Sameal';
		$submit = ' 确 定 ';

		include MD_ROOT.'/admin/'.$file.'.inc.php';
}else{
	include tpl('upinfo', $module);
}


